<?php

class PDOConnection extends PDO{
	
	private static $_instance = null;
	
	private $_engine;
	private $_hostname;
	private $_dbname;
	private $_username;
	private $_password;
	
	public function __construct(){
		$this->_engine		= Config::$opt['db']['engine'];
		$this->_hostname	= Config::$opt['db']['hostname'];
		$this->_dbname		= Config::$opt['db']['dbname'];
		$this->_username	= Config::$opt['db']['username'];
		$this->_password	= Config::$opt['db']['password'];
		
		$dns = $this->_engine.':Database='.$this->_dbname.';Server='.$this->_hostname;
        parent::__construct( $dns, $this->_username, $this->_password);
        //Especifica el manejo de errores por medio de exceptions
        self::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	}
	
	public static function getInstance(){
		if (!(self::$_instance instanceof self)){ 
			self::$_instance=new self(); 
      	} 
		return self::$_instance; 
	}
}